<%@page import="org.willthink.vo.fileupload.FileUploadInfoVo"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>file_List.jsp</title>
	<script type="text/javascript">
		function fileList() {
			location.href = "../fileupload/fileUploadList.think";
		}
		
		function fileUpload() {
			location.href = "../fileupload/fileAddJsp.think";
			//window.open("../fileupload/fileAddJsp.think", "pop", "scrollbar=no, location=no, status=yes, resizable=no,width=400, height=500");
		}
		
		function downlaodFile(index) {
			var obj = document.getElementById("form" + index);
			obj.submit();
		}
		
		function searchTexts() {
			var searchValue = document.frm_Search.searchText.value;
			var optionValue = document.frm_Search.selectOption.value;
			if(searchValue.length != 0 && optionValue == "searchFileName") {
				document.frm_Search.submit();
			} else {
				alert("바보냐?");
			}
		}
		
		function deleteFile(deleteNo) {
			location.href = "../filedelete/filedelete.think?no=" + deleteNo;
		}
	</script>
	<style type="text/css">
		
		#pbgDataRoomTitleArea{width:auto; margin-top:10px; margin-left:10px; margin-bottom:10px; }
		
		#pbgTopMenuArea{width:988px; margin-left: 10px; margin-top:100px;}
		#pbgTopMenu{float:none; margin: 0 auto; width:560px; height:15px; 
		            border:thin; border-style:solid; border-color:black; font-size:12px; font-family:"돋움"; }
		#pbgTopMenu_Number{width:36px; }
		#pbgTopMenu_FileName{width:200px; }
		#pbgTopMenu_Filesize{width:100px; }
		#pbgTopMenu_Regdate{width:100px; }
		#pbgTopMenu_Download{width:60px; }
		#pbgTopMenu_Delete{width:60px; }
		
		#pbgMainMenuArea{width:988px; height:250px; margin-left:10px; margin-top:10px;
		 				 font-size:12px; font-family:"돋움";}
		#pbgMainMenu{float:none; margin: 0 auto; width:556px; height:15px; 
		             font-size:12px; font-family:"돋움"; }
		.pbgMainMenu_Number{width:36px; }
		.pbgMainMenu_FileName{width:200px; }
		.pbgMainMenu_Filesize{width:100px; }
		.pbgMainMenu_Regdate{width:100px; }
		.pbgMainMenu_Download{width:60px; }
		.pbgMainMenu_Delete{width:60px; }
		.elementA{margin-left:17px;}
		
		#pbgButtonArea{width:988px; margin-left:10px; margin-top:10px;}
		#pbgButton{float:none; margin: 0 auto; width:556px; height:20px; 
		           font-size:12px; font-family:"돋움";}
		          
		.elementBtn1{margin-left:450px; font-size:12px; font-family:"돋움";}
		.elementBtn2{font-size:12px; font-family:"돋움";} 
		 
		#pbgPagingArea{width:988px; margin-left:10px; margin-top:10px;}
		#pbgPaging{float:none; margin: 0 auto; width:300px; height:15px; 
		           font-size:12px; font-family:"돋움"; } 
		.pagingElementA{float:none; margin: 0 auto; text-align: center; }
		
		#pbgSearchArea{width:988px; margin-left:10px; margin-top:10px; } 
		#pbgSearch{float:none; margin: 0 auto; width:445px; height:25px;}         
		.pbgSearchElement{font-size:12px; font-family:"돋움"; } 
		
		
	</style>
</head>
<body>
	
	<div id="pbgDataRoomTitleArea">
		<h1>List</h1>
	</div>
		
	<div id="pbgTopMenuArea">
		<div id="pbgTopMenu">
			<div id="pbgTopMenu_Number">번호</div> 
			<div id="pbgTopMenu_FileName">파일이름</div> 
			<div id="pbgTopMenu_Filesize">파일크기</div> 
			<div id="pbgTopMenu_Regdate">등록일</div> 
			<div id="pbgTopMenu_Download">다운로드</div> 
			<div id="pbgTopMenu_Delete">삭제</div>
		</div> 
	</div>
	
	<div id="pbgMainMenuArea">	
	<c:if test="${fn:length(fileList) == 0 }">
		등록된 게시물 또는 검색하고자 하는 게시물이 없습니다.
	</c:if>
	<c:if test="${fn:length(fileList) > 0}">
		<c:forEach var="fileInfo" items="${fileList }" varStatus="step">
			<div id="pbgMainMenu">
				<c:set var="str" value="${fileInfo.file_Name }"/>
				<c:set var="index" value="${fn:indexOf(str, '#') }"/>
				<c:set var="strLength" value="${fn:length(str) }"/>
				<c:set var="realFileName" value="${fn:substring(str, 0, index) }"/> 
				<c:set var="tempFileName" value="${fn:substring(str, index+1, strLength) }"/>  
				<div class="pbgMainMenu_Number">${step.index + 1 }</div>
				<div class="pbgMainMenu_FileName">${realFileName }</div>
				<div class="pbgMainMenu_Filesize">${fileInfo.file_Size }</div>
				<div class="pbgMainMenu_Regdate">${fileInfo.reg_Date }</div>
				<div class="pbgMainMenu_Download">
					<form id="form${step.index + 1 }" action="../filedownload/filedownload.think" method="post">
						<a class="elementA" href="javascript:downlaodFile(${step.index + 1 });">클릭</a>
						<input type="hidden" name="tempFileName" value="${tempFileName }"/>
						<input type="hidden" name="realFileName" value="${realFileName }"/>
					</form>
				</div>
				<div class="pbgMainMenu_Delete">
					<a class="elementA" href="javascript:deleteFile(${fileInfo.file_Pk_No });">삭제</a>
				</div>
			</div>	
		</c:forEach>
	</c:if>
	</div>

	<div id="pbgButtonArea">
		<div id="pbgButton">
			<input class="elementBtn1" type="button" value="등록" onclick="fileUpload();"/>
			<input class="elementBtn2" type="button" value="목록" onclick="fileList();"/>
		</div>
	</div>
	
	<div id="pbgPagingArea">
		<div id="pbgPaging">
		<c:if test="${pagingProcess.blockNumber > 1 }">
			<a class="pagingElementA" href="./${path1 }">[이전]</a>
		</c:if>	
		<c:forEach var="i" begin="${pagingProcess.firstPageNumber }" end="${pagingProcess.totalPageCount }">
			<c:if test="${i <= pagingProcess.endPageNumber }"> 
				<a class="pagingElementA" href="./${path2 }${i }">[${i }]</a>
			</c:if>
		</c:forEach>
		<c:if test="${pagingProcess.endPageNumber < pagingProcess.totalPageCount }">
			<a class="pagingElementA" href="./${path3 }">[다음]</a>
		</c:if>
		</div>
	</div>
	
	<div id="pbgSearchArea">
		<div id="pbgSearch">
			<form name="frm_Search" action="../filesearch/fileSearch.think" method="get">
				<select class="pbgSearchElement" name="selectOption">
					<option value="default">선택</option>
					<option value="searchFileName">파일이름</option>
				</select> 
				<input class="pbgSearchElement" type="text" name="searchText" size="50" maxlength="15"/> 
				<input class="pbgSearchElement" type="button" value="검색" onclick="searchTexts();"/>	
			</form>
		</div>
	</div>	

</body>
</html>